// 定义业务的基本 Columns
import * as constants from 'src/AppConstants'

export const BaseSelection = {
    type: 'selection',
    width: 40,
    align: 'center'
}

export const BaseFixedSelection = {
    type: 'selection',
    width: 40,
    fixed: 'left',
    align: 'center'
}


export const BaseAction = {
    title: '操作',
    key: 'action',
    align: 'center',
    width: 160,
    render (row, column, index) {
        return `<i-button type="text" size="small" icon="edit" @click="onEdit(${index})">编辑</i-button>
                     <i-button type="text" size="small" icon="trash-b" @click="onDelete(${index})">删除</i-button>`
    }
}

export const BaseFixedAction = {
    title: '操作',
    key: 'action',
    align: 'center',
    width: 160,
    fixed: 'right',
    render (row, column, index) {
        return `<i-button type="text" size="small" icon="edit" @click="onEdit(${index})">编辑</i-button>
                     <i-button type="text" size="small" icon="trash-b" @click="onDelete(${index})">删除</i-button>`
    }
}

export const StatusColumn = {
    title: '状态',
    key: 'states',
    width: 80,
    align: 'center',
    render (row, column, index) {
        const isEnabled = row.states == constants.STATUS_ENABLED
        return `<i-switch id="states_${index}" :value="${isEnabled}" @on-change="onStatusToggle" size="large"><span slot="open">启用</span><span slot="close">禁用</span></i-switch>`
    }
}

export const StatusFixedColumn = {
    title: '状态',
    key: 'states',
    width: 80,
    align: 'center',
    fixed: 'right',
    render (row, column, index) {
        const isEnabled = row.states == constants.STATUS_ENABLED
        return `<i-switch id="states_${index}" :value="${isEnabled}" @on-change="onStatusToggle" size="large"><span slot="open">启用</span><span slot="close">禁用</span></i-switch>`
    }
}
